PageClick = function(pageclickednumber, p) {
	var startIndex = p * (pageclickednumber - 1);
	$.ajax( {
		type : "POST",
		url : "admin_work.do?method=findAsks",
		data : "startIndex=" + startIndex + "&pageSize=" + p,
		dataType : "json",
		success : function(data) {
			var totalCount = data.totalCount;
			var pageSize = data.pageSize;
			var currentPage = data.currentPage;
			if (data.items != undefined) {
				showTable(data);
				findZbpls(totalCount, pageSize, currentPage);
			}else{
				$('.move').remove();
				$('#btn5').remove();
				$("#mypage").empty();
				alert("无数据信息");
			}
		},
		error : function() {
			alert("请求出错");
		}
	});
}
function findZbpls(count, p, pageclickednumber) {
	$('#mypage').mypagination(count, {
		callback : PageClick
	}, p, pageclickednumber - 1);
}
function showTable(data){
	var items=data.items;
	if(items!=0){
		$('.move').remove();
		$('#btn5').remove();
		$.each(items,function(i,n){
			var state=n.state;
			var mange="";
			if(state==1)mange="已回复";
			else mange='未处理';
			if(i%2==0){
				var tr='<tr class="move">'
							+'<td align="center" valign="middle" bordercolor="#E7E7E7" bgcolor="#E7E7E7"><input type="checkbox" name="checkbox" id="checkbox" value="'+n.id+'"/></td>'
							+'<td height="23" align="center" valign="middle" bordercolor="#E7E7E7" bgcolor="#E7E7E7"><a href="admin_work.do?method=lookAsk&str='+n.id+'&currentPage='+data.currentPage+'&pageSize='+data.pageSize+'&page=lookAsk">'+n.id+'</a></td>'
							+'<td height="23" align="center" valign="middle" bordercolor="#E7E7E7" bgcolor="#E7E7E7">'+n.asktitle+'</td>'
							+'<td height="23" align="center" valign="middle" bordercolor="#E7E7E7" bgcolor="#E7E7E7"><a href="admin_work.do?method=lookAsk&str='+n.id+'&currentPage='+data.currentPage+'&pageSize='+data.pageSize+'&page=lookAsk">阅读<a></td>'
							+'<td align="center" valign="middle" bordercolor="#E7E7E7" bgcolor="#E7E7E7" style="color:#ff0000"><a href="admin_work.do?method=lookAsk&str='+n.id+'&currentPage='+data.currentPage+'&pageSize='+data.pageSize+'&page=answerAsk">'+mange+'</a></td>'
							+'<td height="23" align="center" valign="middle" bordercolor="#E7E7E7" bgcolor="#E7E7E7">2008-10-1</td>'
					+'</tr>';
				$("#datas").append(tr);
			}else{
				var tr='<tr class="move">'
						+'<td align="center" valign="middle"><input type="checkbox" name="checkbox" id="checkbox" value="'+n.id+'"/></td>'
						+'<td height="23" align="center" valign="middle"><a href="admin_work.do?method=lookAsk&str='+n.id+'&currentPage='+data.currentPage+'&pageSize='+data.pageSize+'&page=lookAsk">'+n.id+'</a></td>'
						+'<td height="23" align="center" valign="middle">'+n.asktitle+'</td>'
						+'<td height="23" align="center" valign="middle"><a href="admin_work.do?method=lookAsk&str='+n.id+'&currentPage='+data.currentPage+'&pageSize='+data.pageSize+'&page=lookAsk">阅读<a></td>'
						+'<td align="center" valign="middle"><span style="color:#3caa0d"><a href="admin_work.do?method=lookAsk&str='+n.id+'&currentPage='+data.currentPage+'&pageSize='+data.pageSize+'&page=answerAsk">'+mange+'</a></span></td>'
						+'<td height="23" align="center" valign="middle">2008-10-1</td>'
					+'</tr>';
				$("#datas").append(tr);
			}
			var tr='<tr class="move">'
						+'<td height="12" align="center" valign="middle">&nbsp;</td>'
						+'<td height="12" align="center" valign="middle">&nbsp;</td>'
						+'<td height="12" align="center" valign="middle">&nbsp;</td>'
						+'<td height="12" align="center" valign="middle">&nbsp;</td>'
						+'<td align="center" valign="middle">&nbsp;</td>'
						+'<td height="12" align="center" valign="middle">&nbsp;</td>'
				   +'</tr>';
			$("#datas").append(tr);
		});
		var input='<input type="button" id="btn5" value="删除所选" onclick="deleteAsk('+data.currentPage+','+data.pageSize+','+data.totalCount+')"/>';
		$("#button").append(input);
	}
}
function deleteAsk(currentPage,pageSize,totalCount){
	var pageNum=Math.ceil(totalCount/pageSize);
	var str="";
	var i=0;
    $(":checkbox[checked]").each(function(){
        str+=$(this).val()+",";
        i=i+1;
    })
    if(i==0){
    	alert("至少选择一条数据");
    	return false;
    }
    str=str.substring(0,str.length-1);
    var url="admin_work.do?method=deleteAsk";
	$.post(url,"str="+str,function(data){
		if(data==-1){
			alert("删除失败");
		}else if(data==0){
			if(currentPage==pageNum&&(totalCount%pageSize==i||pageSize==1)){
				currentPage=currentPage-1;
			}
			if(currentPage==0)currentPage=1;
			PageClick(currentPage,pageSize);
			alert("删除成功");
		}
	},"json");
}
